import test from 'ava';

import browserEnv from 'browser-env';

import query2url from '../../dist/browser/url/query2url';
import get_query from '../../../dist/framework/utils/get-query';

browserEnv();

test('query2url', (t) => {
	t.is(query2url({ a: 'abc', b: 123, c: true, d: JSON.stringify({ e: 546 }), e: JSON.stringify([1, 2, 3]), f: null, g: undefined }), 'about:blank?a=abc&b=123&c=true&d=%7B%22e%22%3A546%7D&e=%5B1%2C2%2C3%5D&f=null&g=undefined');
	t.is(query2url({ a: 'abc', b: 123, c: true, d: JSON.stringify({ e: 546 }), e: JSON.stringify([1, 2, 3]), f: null, g: undefined }, 'http://www.baidu.com'), 'http://www.baidu.com?a=abc&b=123&c=true&d=%7B%22e%22%3A546%7D&e=%5B1%2C2%2C3%5D&f=null&g=undefined');

	t.is(query2url({ a: 'abc', b: 123, c: true, d: JSON.stringify({ e: 546 }), e: JSON.stringify([1, 2, 3]), f: null, g: undefined }, 'http://www.baidu.com?ticket=2'), 'http://www.baidu.com?a=abc&b=123&c=true&d=%7B%22e%22%3A546%7D&e=%5B1%2C2%2C3%5D&f=null&g=undefined');

	t.is(query2url({}, 'http://www.baidu.com?ticket=2'), 'http://www.baidu.com');
});

test('get-query', (t) => {
	const v1 = get_query('http://www.baidu.com?a=abc&b=123&c=true&d=%7B%22e%22%3A546%7D&e=%5B1%2C2%2C3%5D&ticket=2&f=null');
	console.log(v1);
	t.deepEqual(v1, { a: 'abc', b: '123', c: 'true', d: JSON.stringify({ e: 546 }), e: JSON.stringify([1, 2, 3]), f: 'null', ticket: '2' });


	const v2 = get_query('http://www.baidu.com?fd=');
	t.deepEqual(v2, { fd: '' });

	const v3 = get_query('http://www.baidu.com');
	t.deepEqual(v3, {});
})
